package org.ring.csr.core;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * 
 * @author Ray Ling
 */
public class CheckNode implements Iterable<CheckReport> {
    private final String type;
    private final String path;
    private final List<CheckReport> checkReports;

    public CheckNode(final String type, final String path) {
	this.type = type;
	this.path = path;
	this.checkReports = new ArrayList<CheckReport>();
    }

    public final String getType() {
	return type;
    }

    public final String getPath() {
	return path;
    }
    
    public final void addReport(final CheckReport checkReport) {
	checkReports.add(checkReport);
    }

    public final Iterator<CheckReport> iterator() {
	return checkReports.iterator();
    }

    public final boolean combine(final CheckNode node) {
	if (type.equals(node.getType()) && path.equals(node.getPath())) {
	    checkReports.addAll(node.checkReports);
	    return true;
	}
	return false;
    }

    public final int size() {
	return checkReports.size();
    }

    public final String toString() {
	return "[" + type + "]" + path;
    }
}
